package com.yjps.house.service;

import com.yjps.house.dao.HistoryDao;
import com.yjps.house.model.PublishHistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

@Service("historyService")
public class HistoryService {
    @Autowired
    HistoryDao historyDao;

    @Transactional
    public boolean updatePublishHistory(PublishHistory history){
        String hql="update PublishHistory ph set ph.agentsId = :agentsId , ph.houseId = :houseId," +
                "ph.time= :time, ph.handleTime= :handleTime, ph.handleResult = :handleResult," +
                "ph.isValid = :isValid, ph.remark = :remark where ph.id = :id";

        Map<String,Object> params = new HashMap<>();
        params.put("agentsId",history.getAgentsId());
        params.put("houseId", history.getHouseId());
        params.put("time",history.getTime());
        params.put("handleTime",history.getHandleTime());
        params.put("handleResult",history.getHandleResult());
        params.put("isValid",history.getIsValid());
        params.put("remark",history.getRemark());
        params.put("id", history.getId());

        int affectRows=historyDao.excute(hql,params);
        if (affectRows==0){
            return false;
        }
        return true;
    }
}
